package com.ruoyi.manage.CL253Api.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.CL253Api.MessageApi;
import com.ruoyi.common.utils.CLUtils;
import com.ruoyi.manage.CL253Api.SendMessageApi;
import com.ruoyi.manage.CL253Api.request.SendMessageRequest;
import com.ruoyi.manage.CL253Api.response.SendMessageResponse;

import java.util.Map;

/**
 * @Author: wwy
 * @Date: 2021/3/4 11:42
 */
public class SendMessageClient implements SendMessageApi {
    @Override
    public SendMessageResponse sendMessageExecute(SendMessageRequest sendMessageRequest) {
        MessageApi messageApi = CLUtils.getMessageApi();
        JSONObject jsonObject = messageApi.sendMessage(sendMessageRequest.getPhone(), sendMessageRequest.getMessage(), sendMessageRequest.getOption());
        Map map = jsonObject.toJavaObject(Map.class);
        String code = String.valueOf(map.get("code"));
        SendMessageResponse sendMessageResponse = new SendMessageResponse();
        if("0".equals(code)){
            //成功
            sendMessageResponse.setSuccess(true);
        }else{
            //失败
            sendMessageResponse.setSuccess(false);
        }
        return sendMessageResponse;
    }
}
